<!-- 137 -->
<template>
  <div>
    <a-space class="common-button-group">
      <a-button type="primary" :loading="searchBtnLoading" @click="getList">{{ $t('common_query') }}</a-button>
    </a-space>
    <t-query-form layout="inline"
      ref="queryForm"
      group="passGlassByMachine"
      :model="queryForm"
      >
      <a-row
        :gutter="[16, 0]"
      >
        <a-col :span="6">
          <a-form-item :label="$t('T9_shopId')" name="shopId" prop="shopId" :rules="{ required: true, message: '请选择Shop Id', trigger: 'change'}">
            <a-select v-model:value="queryForm.shopId" class="select-width" @change="changeShopId">
              <a-select-option v-for="item in shopIdArr"
              :key="item.shopId" :value="item.shopId">
              {{item.shopId}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('T9_bayId')" name="BayID">
            <a-select v-model:value="queryForm.bayId" class="select-width" @change="changeBayId">
              <a-select-option v-for="item in bayIdArr"
              :key="item.bayId" :value="item.bayId">
              {{item.bayId}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('T9_eqpId')" name="EQPID">
            <a-select v-model:value="queryForm.eqpId" class="select-width">
              <a-select-option v-for="item in eqpIdArr"
              :key="item.eqpId" :value="item.eqpId">
              {{item.eqpId}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('T9_productType')" name="productType">
            <a-select v-model:value="queryForm.productType" class="select-width" @change="changeProductType">
              <a-select-option v-for="item in productTypeArr"
              :key="item.enumValue" :value="item.enumValue">
              {{item.enumValue}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('T9_productId')" name="productId">
            <a-select v-model:value="queryForm.productId" class="select-width">
              <a-select-option v-for="item in productIdArr"
              :key="item.productId" :value="item.productId">
              {{item.productId}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('T9_ownerType')" name="ownerType">
            <a-select v-model:value="queryForm.ownerType" class="select-width" @change="changeOwnerType">
              <a-select-option v-for="item in ownerTypeArr"
              :key="item.enumName" :value="item.enumName">
              {{item.enumName}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('t9_owner')" name="owner">
            <a-select v-model:value="queryForm.owner" class="select-width">
              <a-select-option v-for="item in ownerArr"
              :key="item.enumValue" :value="item.enumValue">
              {{item.enumValue}}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item :label="$t('t9_date')" name="date">
            <a-range-picker
              :show-time="{ format: 'HH:mm:ss' }"
              :default-value="queryForm.Date"
              format="YYYY-MM-DD HH:mm:ss"
              @ok="onChange"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </t-query-form>
    <a-descriptions
      bordered
      :column="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
    >
      <a-descriptions-item :label="$t('T9_cstOutQty')">{{ table.cstOutQty }}</a-descriptions-item>
      <a-descriptions-item :label="$t('T9_glassOutQty')">{{ table.glassOutQty }}</a-descriptions-item>
      <a-descriptions-item :label="$t('T9_panelOutQty')">{{ table.panelOutQty }}</a-descriptions-item>
    </a-descriptions>
    <a-row type="flex" justify="space-between" align="middle" class="global-oper-row mt-2">
      <a-col :span="15" class="global-oper-row-title">{{ $t('T9_cstList') }}</a-col>
      <a-col :span="8" class="global-oper-row-extra">
        <a-button>{{ $t('t9_toExcel') }}</a-button>
      </a-col>
    </a-row>
    <t-table
      :data="table.cstListByMachineDTOList"
    >
      <t-column field="eventTime" :title="$t('T9_eventTime')" />
      <t-column field="eventName" :title="$t('T9_eventName')" />
      <t-column field="eventUser" :title="$t('T9_eventUser')" />
      <t-column field="cstId" :title="$t('T9_cstId')" />
      <t-column field="glassQty" :title="$t('T9_glassQty')" />
      <t-column field="panelQty" :title="$t('T9_panelQty')" />
      <t-column field="productType" :title="$t('T9_productType')" />
      <t-column field="owner" :title="$t('T9_owner')" />
      <t-column field="ownerType" :title="$t('T9_ownerType')" />
      <t-column field="lotGrade" :title="$t('T9_cstGrade')" />
      <t-column field="priority" :title="$t('T9_priority')" />
      <t-column field="runMode" :title="$t('T9_runMode')" />
      <t-column field="productId" :title="$t('T9_productId')" />
      <t-column field="productVer" :title="$t('T9_productVer')" />
      <t-column field="route" :title="$t('T9_route')" />
      <t-column field="oldOperation" :title="$t('T9_oldOperation')" />
      <t-column field="operation" :title="$t('T9_operation')" />
      <t-column field="description" :title="$t('T9_desc')" />
      <t-column field="eqpId" :title="$t('T9_eqpId')" />
      <t-column field="shipGroupId" :title="$t('T9_shipGroupId')" />
      <t-column field="groupId" :title="$t('T9_groupId')" />
      <t-column field="name" :title="$t('T9_holdState')" />
      <t-column field="fastRunFlag" :title="$t('T9_fastRunGlassQty')" />
    </t-table>
  </div>
</template>

<script>
  import { defineComponent } from 'vue'
  import moment from 'moment'
  import {
    getShopId,
    getBayId,
    getEqpId,
    getProductType,
    getProductId,
    getOwnerType,
    getOwnerId,
    getList
  } from '@/api/common'
  import { getCurrentDate } from '@/utils/utils'

  export default defineComponent({
    name: 'PassGlassByMachine',
    components: {},
    data() {
      return {
        searchBtnLoading: false,
        table: {
          list: []
        },
        shopIdArr: [],
        bayIdArr: [],
        eqpIdArr: [],
        productTypeArr: [],
        productIdArr: [],
        ownerTypeArr: [],
        ownerArr: [],
        queryForm: {
          shopId: 'Cell',
          bayId: '',
          eqpId: '',
          productType: '',
          productId: '',
          ownerType: '',
          owner: '',
          Date: []
        }
      }
    },
    computed: {},
    watch: {},
    created() {
      this.getShopId()
      this.getProductType()
      this.getOwnerType()
      this.getList()
      this.queryForm.Date = [moment(getCurrentDate(), 'YYYY-MM-DD HH:mm:ss'), moment(getCurrentDate(1), 'YYYY-MM-DD HH:mm:ss')]
    },
    methods: {
      onChange(value, dates) {
        this.queryForm.Date = value
        console.log('Selected Time: ', value)
        console.log('Formatted Selected Time: ', dates)
      },
      getList() {
        const obj = {
          dtoName: 'CstListByMachineDTO',
          startTime: this.queryForm.Date.length !== 0 ? this.queryForm.Date[0].format('YYYY-MM-DD HH:mm:ss') : null,
          endTime: this.queryForm.Date.length !== 0 ? this.queryForm.Date[1].format('YYYY-MM-DD HH:mm:ss') : null,
          ownerId: this.queryForm.ownerId,
          ownerType: this.queryForm.ownerType,
          productId: this.queryForm.productId,
          productType: this.queryForm.productType,
          queryId: 'GetThroughputByMachine',
          shopId: this.queryForm.shopId,
          version: '80001',
          menuName: 'passGlassByMachine',
          usage: 'queryCstList'
        }
        getList(obj).then(res => {
          this.table = res
        })
      },
      handleSearch() {},
      changeShopId(val) {
        if (val) {
          this.getBayId()
        }
      },
      changeProductType(val) {
        if (val) {
          this.getProductId()
        }
      },
      changeOwnerType(val) {
        if (val) {
          this.getOwner()
        }
      },
      changeBayId(val) {
        if (val) {
          this.getEqpId()
        }
      },
      getShopId() {
        const params = {
          userGroup: 'CellPIOper'
        }
        getShopId(params).then(res => {
          this.shopIdArr = res
        })
      },
      getBayId() {
        const params = {
          shopId: this.queryForm.shopId
        }
        getBayId(params).then(res => {
          this.bayIdArr = res
        })
      },
      getEqpId() {
        const params = {
          bayId: this.queryForm.bayId,
          shopId: this.queryForm.shopId
        }
        getEqpId(params).then(res => {
          this.eqpIdArr = res
        })
      },
      getProductType() {
        getProductType().then(res => {
          this.productTypeArr = res
        })
      },
      getProductId() {
        const params = {
          productType: this.queryForm.productType,
          shopId: this.queryForm.shopId
        }
        getProductId(params).then(res => {
          this.productIdArr = res
        })
      },
      getOwnerType() {
        getOwnerType().then(res => {
          this.ownerTypeArr = res
        })
      },
      getOwner() {
        const params = {
          ownerType: this.queryForm.ownerType,
          shopId: this.queryForm.shopId
        }
        getOwnerId(params).then(res => {
          this.ownerArr = res
        })
      }
    }
  })
</script>
<style lang="less" scoped>
</style>
